//
//  caigouqiyeproductxqTableViewCell.m
//  BAOASystem
//
//  Created by michael on 2018/3/7.
//  Copyright © 2018年 czd. All rights reserved.
//
#import "qiyecaigouxqCollectionViewCell.h"
#import "qiyecaigouViewController.h"
#import "productCollectionViewCell.h"
#import "qiyeproductxqTableViewCell.h"
#import "caigouqiyeproductxqTableViewCell.h"
#import "caigouxqViewController.h"
@implementation caigouqiyeproductxqTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
  _view0 = [[UIView alloc]init];
    _view0.frame = CGRectZero;
       [self.contentView addSubview:_view0];
 _label = [[UILabel alloc]init];
    _label.frame = CGRectZero;
        _label.numberOfLines = 0;
      [_label setFont:[UIFont systemFontOfSize:14]];
       [self.view0 addSubview:_label];
    _view = [[UIView alloc]init];
    _view.frame = CGRectZero;
       [self.view0 addSubview:_view];
    
  _view2 = [[UIView alloc]init];
    _view2.frame = CGRectZero;
       [self.contentView addSubview:_view2];
    
        self.collectionView.frame =CGRectZero;

 [self.contentView addSubview:self.collectionView];

}

return self;

}
-(UICollectionView *)collectionView{
if (!_collectionView) {
  UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake((KScreenWidth)/2,150);

    layout.minimumLineSpacing = 0;
   layout.minimumInteritemSpacing = 0;
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    NSArray *list = _dic[@"ctgpdlist"];
int num =(int) ceil(list.count/2.0);
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 30, KScreenWidth, num*150) collectionViewLayout:layout];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.pagingEnabled = true;
//    _collectionView.scrollEnabled=NO;
    _collectionView.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];
//        _collectionView.backgroundColor = [UIColor whiteColor];

//[_collectionView registerNib:[UINib nibWithNibName:@"productCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"productCollectionViewCell"];
    [_collectionView registerClass:[qiyecaigouxqCollectionViewCell class] forCellWithReuseIdentifier:@"productCollectionViewCell"];

//self.collectionView.alwaysBounceVertical = YES;

    _collectionView.showsHorizontalScrollIndicator = false;
    
}
return _collectionView;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{


 static NSString* cellId0 = @"productCollectionViewCell";
    qiyecaigouxqCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellId0 forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    NSArray *list = _dic[@"ctgpdlist"];

   cell.dic =list [indexPath.row];
   [cell layoutSubviews];
    return cell;

   
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    NSArray *list = _dic[@"ctgpdlist"];
NSLog(@"111");
NSDictionary *dic =list [indexPath.row];
NSString *pdid =dic[@"id"];
caigouxqViewController *vc = [[caigouxqViewController alloc]init];
//shangpinxqViewController *vc = [[shangpinxqViewController alloc]init];
vc.pdid = pdid;
vc.hidesBottomBarWhenPushed = YES;
[self.ViewController.navigationController pushViewController:vc animated:YES];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
NSArray *list = _dic[@"ctgpdlist"];

    return list.count;

}
-(void)setDic:(NSDictionary *)dic{
_dic = dic;
_label.frame = CGRectMake(0, 0, KScreenWidth, 30);
_label.textAlignment = 1;
_label.text = _dic[@"ctgName"];
NSArray *list = _dic[@"ctgpdlist"];
int num =(int) ceil(list.count/2.0);
_collectionView.frame = CGRectMake(0, _label.bottom, KScreenWidth, num*150);

[self.collectionView reloadData]; //重新换数据源的时候 记得重回用的cell上的

}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

